package com.vogue.supplymall.order.domain.service.impl;

import com.vogue.ssm.database.dao.BaseDao;
import com.vogue.supplymall.order.domain.dao.OrderPaymentDao;
import com.vogue.supplymall.order.domain.model.OrderPayment;
import com.vogue.supplymall.order.domain.service.OrderPaymentService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

/**
 * The type Order payment serviceimpl.
 *
 * @aouthor: zhangliang
 * @date: Create in 2018-02-05
 */
@Service("orderPaymentService")
@Transactional
public class OrderPaymentServiceImpl extends BaseServiceImpl<OrderPayment, Long> implements OrderPaymentService {
	/**
	 * The constant log.
	 */
	public static final Logger LOGGER_ORDERPAYMENTSERVICEIMPL = LoggerFactory.getLogger(OrderPaymentServiceImpl.class);

	@Resource
	private OrderPaymentDao orderPaymentDao;

	/**
	 * Instantiates a new Order payment serviceimpl.
	 *
	 * @param baseDao
	 *            the base dao
	 */
	public OrderPaymentServiceImpl(BaseDao<OrderPayment, Long> baseDao) {
		super(baseDao);
	}

	@Override
	public Optional<OrderPayment> getForOrderId(Long orderId) {
		List<OrderPayment> payments = orderPaymentDao.getForOrderId(orderId);
		if (null != payments) {
			return payments.stream().findFirst();
		}
		return Optional.empty();
	}

}
